<!--
 * @Author: MrLee
 * @Date: 2024-08-24 08:55:14
 * @LastEditors: MrLee
 * @LastEditTime: 2024-09-02 20:34:50
 * @Description: 请填写简介
-->
<template>
  <custom-navbar title="更多" :auto-back="true" left-icon-color="#303133" />
  <up-gap height="30rpx" />
  <view class="px-24rpx">
    <infocard :user-info-list="moreList" @actionTmp="oneAction" />
  </view>
  <up-gap height="30rpx" />
  <view class="px-24rpx">
    <infocard :user-info-list="moreListSecend" @actionTmp="oneAction" />
  </view>
  <up-gap height="30rpx" />
  <view class="px-24rpx">
    <infocard :user-info-list="moreListLast" @actionTmp="oneAction" />
  </view>
  <up-picker :show="show" :columns="columns" @confirm="confirm" @cancel="show = false"></up-picker>
</template>

<script setup lang="ts">
  import infocard from '@/pages/components/infocard/index.vue';
  import { userMore, updateUserInfo } from '@/api/user';

  const moreList = reactive([
    {
      title: '基本信息',
      value: '',
      valueType: 'text',
      jumpUrl: '/pages/userinfo/index'
    },
    {
      title: '教育经历',
      value: '',
      valueType: 'text',
      rigthIco: true,
      jumpUrl: '/pages/tab/home/more/educationExperience'
    },
    {
      title: '求职状态',
      value: '',
      rigthIco: true,
      valueType: 'text',
      options: [["正在看机会", "已找到工作", "离职状态"]],
    },
  ]);
  const moreListSecend : any = reactive([
    {
      title: '求职偏好',
      value: '',
      valueType: 'text',
      rigthIco: true,
      jumpUrl: '/pages/tab/home/more/preference'
    },
    {
      title: '我的简历',
      value: '',
      valueType: 'text',
      rigthIco: true,
      jumpUrl: '/pages/userinfo/resume'
    },
    {
      title: '感兴趣的职位',
      value: '',
      rigthIco: true,
      valueType: 'text',
      jumpUrl: '/pages/common/interested/index'
    },
  ]);
  const moreListLast = reactive([
    {
      title: '常用语',
      value: '   ',
      valueType: 'text',
      rigthIco: true,
      jumpUrl: '/pages/tab/home/more/comPhrases'
    },
    {
      title: '求职隐私保护',
      value: '',
      valueType: 'text',
      rigthIco: true,
      jumpUrl: '/pages/tab/home/more/privacy'
    },
  ]);

  let columns = reactive([]);
  let show = ref(false)
  const oneAction = (params) => {
    console.log('oneAction：：：求职状态', params);
    if (params.jumpUrl) {
      uni.navigateTo({
        url: params.jumpUrl,
      });
    }
    if (params.options) {
      show.value = true;
      columns = params.options
    }
  }

  const confirm = async (v) => {
    console.log(v)
    show.value = false;
    try {
      const result = await updateUserInfo({
        job_status: v.value[0] === "正在看机会" ? 1 : v.value[0] === "已找到工作" ? 2 : 3
      });
      console.log("result", result);
      getMoreInfo()
    } catch (e) {
      console.log(e);
    }
  };

  async function getMoreInfo() {
    let r = await userMore();
    console.log('首页-更多 res:::', r);
    //vue3传递result的值到子组件JobList中的属性jobList中
    let rr = {
      user_info_status: r.user_info_status,
      job_status: r.job_status,
      intention_count: r.intention_count,   //求职偏好数量
      resume_count: r.resume_count, //我的简历数量
      like_count: r.like_count, //感兴趣的职位数量
      qualifications: ""
    }
    let qualifications = ''
    if (r.education_info.length == 1) {
      qualifications = '未完成/未完成'
    } else if (r.education_info.length == 2) {
      qualifications = '未完成'
    }
    for (let j = 0; j < r.education_info.length; j++) {
      qualifications += '/' + r.education_info[j].qualification
    }
    let intertion_content = rr.intention_count > 0 ? r.intention_count + '个求职偏好' : '未设置'
    moreListSecend[0].value = intertion_content
    let resume_content = rr.resume_count > 0 ? r.resume_count + '份简历' : '未上传'
    moreListSecend[1].value = resume_content
    moreListSecend[2].value = rr.like_count + '个'

    moreList[0].value = rr.user_info_status == 1 ? '已完成' : '未完成'   //基本用户信息
    moreList[1].value = qualifications  //教育经历
    moreList[2].value = rr.job_status == 1 ? '正在看机会' : rr.job_status == 2 ? '已找到工作' : '离职状态' //求职状态
  }

  onLoad(() => {
    getMoreInfo()
  });
</script>
